exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.Service {
    constructor() {
        super();
        this.StaticsOrgModel = this.db['temp_statics_org'];
    }

    /**
     * 得到所需统计的部门
     *
     * @returns
     */
    getStaticsOrgList(module) {
        var _this = this;

        return _asyncToGenerator(function* () {
            try {
                const Res = yield _this.StaticsOrgModel.findAll({
                    where: { module: module, is_statistics: 1 }
                });
                return Res;
            } catch (error) {
                return _this.exceptionService.handleError(error);
            }
        })();
    }

    /**
     * 更新所统计的部门
     *
     * @returns
     */
    upsertStaticsOrg(data) {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            let dataList = data.org_id;
            let dataModelList = [];
            dataList.map(function (item) {
                dataModelList.push({ org_id: item, is_statistics: 1, module: data.module });
            });
            try {
                yield _this2.StaticsOrgModel.update({ is_statistics: 0 }, { where: { module: data.module } });
                dataModelList.map((() => {
                    var _ref = _asyncToGenerator(function* (item) {
                        yield _this2.StaticsOrgModel.upsert(item);
                    });

                    return function (_x) {
                        return _ref.apply(this, arguments);
                    };
                })());

                return {};
            } catch (error) {
                return _this2.exceptionService.handleError(error);
            }
        })();
    }
};